package com.hsoft.zhxy.common.exception;

import com.alibaba.fastjson.JSONObject;

/**
 * All rights Reserved, Designed By 哈尔滨工业大学软件工程股份有限公司
 * 
 * @Title: ErrorResultBody
 * @Description: 返回格式
 * @author: menglingwei
 * @date: 2020年5月16日 下午1:10:48
 */
public class ExcpResultBody {
    /**
     * 响应代码
     */
    private String code;

    /**
     * 响应消息
     */
    private String message;

    /**
     * 响应开发者错误日志消息
     */
    private Object data;

    public ExcpResultBody() {
    }

    public ExcpResultBody(ExcpInfoInterface errorInfo) {
        this.code = errorInfo.getResultCode();
        this.message = errorInfo.getResultMsg();
    }


    /**
     * 失败
     */
    public static ExcpResultBody error(ExcpInfoInterface errorInfo, Object e) {
        ExcpResultBody rb = new ExcpResultBody();
        rb.setCode(errorInfo.getResultCode());
        rb.setMessage(errorInfo.getResultMsg());
        rb.setData(e);
        return rb;
    }

    /**
     * 自定义失败返回信息
     */
    public static ExcpResultBody error(String code, String message) {
        ExcpResultBody rb = new ExcpResultBody();
        rb.setCode(code);
        rb.setMessage(message);
        rb.setData("");
        return rb;
    }

    /**
     * 自定义失败返回信息
     */
//    public static ResultBody error(String message) {
//        ResultBody rb = new ResultBody();
//        rb.setCode("-1");
//        rb.setMessage(message);
//        rb.setData("");
//        return rb;
//    }

    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }
    
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

}